Skip to content

Accurate time breakdown: cap suspensions + union parallel spans (+ parallelism insight)#10

Open
wan-huiyan wants to merge 4 commits into
dioptx:mainfrom
wan-huiyan:upstream/time-and-insight
Open

Accurate time breakdown: cap suspensions + union parallel spans (+ parallelism insight)#10
wan-huiyan wants to merge 4 commits into
dioptx:mainfrom
wan-huiyan:upstream/time-and-insight

Conversation

@wan-huiyan
Copy link
Copy Markdown

Three related time-accounting changes (grouped to keep review manageable and avoid pairwise conflicts — all touch analyzer.ts/analyzer.test.ts):

  1. Cap "Claude thinking" gaps at 10 min — the user→assistant and tool_result→assistant gaps were uncapped, so a mid-turn suspension (overnight pause / credit stall / handoff) read as hours of "thinking." Excess → humanAway. On a 16h session this moved ~9h out of thinking.
  2. Union, not sum, for parallel tool/subagent spans — fan-out in one turn (e.g. a panel of subagents) was double-counted; active-time could exceed 100%. Now aggregated by wall-clock interval union.
  3. Parallel-subagent benefit insight — surfaces the value of fan-out: ⚡ Parallel subagents: 5 ran in 38m wall (53m of work · 1.4× concurrent · saved 15m vs sequential), shown only on real overlap.
    Plus a union(segments) ≤ wall-clock span invariant test.

All self-contained; 98 tests pass, tsc clean. Supersedes the separate #6/#7 (consolidated here).

🤖 Generated with Claude Code

wan-huiyan and others added 4 commits May 29, 2026 13:15
…unted as thinking (#4)

Only the assistant-end→user gap was capped by IDLE_THRESHOLD_MS. The
user→assistant and tool_result→assistant gaps (both → claudeThink) were
uncapped, so any long pause landing mid-turn (overnight gap after a tool
result, credit stall, remote-control handoff) was reported as hours of
"Claude thinking."

Add THINK_CAP_MS (10 min) and an emitThink() helper that caps the thinking
slice and books the remainder as humanAway. On a real 16h session with
overnight gaps this moves ~9h out of "thinking" (11h34m → 2h35m) into away
time. +3 unit tests; all 90 pass; tsc clean.
…t sum (#3)

computeEnhancedStats emitted one segment per tool/agent and summed their
durations. When tools or subagents are fanned out in a single assistant turn
(e.g. a 5-agent review panel, or parallel Read/Bash calls), those segments
overlap in wall-clock time, so summing double-counts the concurrency — the
'Subagents' bar reported cumulative agent-seconds, not real elapsed time, and
the active-time percentages could sum to >100% (e.g. 109%).

Aggregate toolExec and subagent by wall-clock interval UNION instead:
  - subagent = time with >=1 subagent open
  - toolExec = busy-with-a-tool time NOT already counted as subagent
    (subagent wins the rare cross-kind overlap, e.g. Agent + Bash in one turn)
claudeThink / planning / humanWait / humanAway are emitted as sequential,
non-overlapping slices and are still summed (unchanged).

On a fan-out-heavy session this dropped reported subagent time from ~53m
(sum of 19 overlapping agents) to ~38m (true elapsed), and the breakdown now
sums to ~100% instead of 109%. The per-call 'Tools' latency table (avg/p50/p95)
is computed separately and is intentionally unchanged.

Tests: 3 cases (parallel agents → union not sum; parallel non-agent tools →
union; sequential agents still add up). 90/90 tests pass.
Time accounting must aggregate possibly-overlapping phase spans by wall-clock
UNION, not SUM — parallel tool/subagent spans (two tool_use in one assistant
message share the same start) overlap, so a naive sum overcounts and can exceed
the session's wall-clock. This adds a regression guard:

- union(enhancedSegments) ≤ (max endTime − min startTime), always
- a parallel-tools scenario where naiveSum > span (proves the overlap is real,
  so the invariant is non-vacuous) while union ≤ span
- each segment is a valid non-negative interval (endTime ≥ startTime,
  durationMs === endTime − startTime)

Pure test addition (no src change). Full suite 89 passing; tsc clean. Came out
of an independent wall/active/away recompute that used exactly this union-vs-sum
cross-check to reconcile against the live tool.

Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
)

Surfaces the value of fanning out: the subagent phase is aggregated by
wall-clock union (correct elapsed time), but sum−union = time saved by running
agents concurrently and sum/union = effective concurrency. Adds an Insights
line shown only when ≥2 subagents actually overlapped (saved >1s), so
sequential sessions get no spurious line. Exports unionMs from analyzer for
reuse. +3 formatter tests. 102 pass; tsc clean.
@wan-huiyan
Copy link
Copy Markdown
Author

wan-huiyan commented May 29, 2026

Hi @dioptx, thank you so much for cctime — it's genuinely become part of my daily Claude Code workflow ❤️

I found a few accuracy issues + small improvements and (apologies for the churn 🙈) opened a bunch of PRs while iterating. I've now consolidated everything into 3 focused PRs to keep review manageable:

Each is self-contained with tests + tsc clean. No pressure to take all/any — happy to split, rescope, or drop anything 😊 Thank you again for building this! 💜

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant